﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mangosoft.DiceCopy.Domain.MainBoundedContext.Aggregates.JobseekerAgg;
using Mangosoft.DiceCopy.Domain.MainBoundedContext.Aggregates.EducationAgg;
using System.ComponentModel.DataAnnotations;
using Mangosoft.DiceCopy.Domain.Seedwork;
using Mangosoft.DiceCopy.Domain.MainBoundedContext.Aggregates.SkillAgg;

namespace Mangosoft.DiceCopy.Domain.MainBoundedContext.Aggregates.ResumeAgg {
    public class Resume : Entity, IValidatableObject {
        #region Members
        HashSet<Education> _educations;
        //HashSet<Skill> _skills;
        //HashSet<Employment> _employments;
        //HashSet<Certification> _certifications;
        #endregion

        #region Properties
        ///<summary>
        ///
        ///</summary>
        public string Name { get; set; }

        ///<summary>
        ///
        ///</summary>
        public string ResumeNumber { get; set; }

        ///<summary>
        ///个人信息中有的，作为默认值
        ///</summary>
        public string FirstName { get; set; }

        ///<summary>
        ///
        ///</summary>
        public string LastName { get; set; }

        ///<summary>
        ///标准头像
        ///</summary>
        public Guid? AvatarId { get; set; }

        ///<summary>
        ///
        ///</summary>
        public string Phone { get; set; }

        ///<summary>
        ///
        ///</summary>
        public string Mobile { get; set; }

        ///<summary>
        ///
        ///</summary>
        public int ProvinceCode { get; set; }

        ///<summary>
        ///
        ///</summary>
        public int CityCode { get; set; }

        ///<summary>
        ///自填区县及街道地址
        ///</summary>
        public string Address { get; set; }

        ///<summary>
        ///
        ///</summary>
        public string Zip { get; set; }

        ///<summary>
        ///
        ///</summary>
        public string Gender { get; set; }

        ///<summary>
        ///
        ///</summary>
        public DateTime? Birthdate { get; set; }

        ///<summary>
        ///HighestEducation
        ///</summary>
        public int EducationLevelCode { get; set; }

        ///<summary>
        ///
        ///</summary>
        public int? YearsExperienceCode { get; set; }

        ///<summary>
        ///
        ///</summary>
        public string QQ { get; set; }

        ///<summary>
        ///
        ///</summary>
        public string Blog { get; set; }

        ///<summary>
        ///社交网络1；默认微博
        ///</summary>
        public string SNS1 { get; set; }

        ///<summary>
        ///社交网络2
        ///</summary>
        public string SNS2 { get; set; }

        ///<summary>
        ///备用
        ///</summary>
        public string SNS3 { get; set; }

        ///<summary>
        ///
        ///</summary>
        public string Biography { get; set; }

        ///<summary>
        ///
        ///</summary>
        public string Tags { get; set; }

        ///<summary>
        ///Current
        ///</summary>
        public int? IndustryCode { get; set; }

        ///<summary>
        ///
        ///</summary>
        public string DesiredPosition { get; set; }

        ///<summary>
        ///“；”区分
        ///</summary>
        public int? PositionTypeCode { get; set; }

        ///<summary>
        ///年薪范围 5000每档
        ///</summary>
        public int? AnnualPayCode { get; set; }

        ///<summary>
        ///
        ///</summary>
        public string PreferredLocations { get; set; }

        ///<summary>
        ///
        ///</summary>
        public int? WillingToTravelCode { get; set; }

        ///<summary>
        ///
        ///</summary>
        public bool? WillingToRelocate { get; set; }

        ///<summary>
        ///
        ///</summary>
        public bool? WillingToTelecommute { get; set; }

        ///<summary>
        ///
        ///</summary>
        public int? CanStartCode { get; set; }

        ///<summary>
        ///暂时不用
        ///</summary>
        public bool? FromThirdParty { get; set; }

        ///<summary>
        ///1-普通；2-学生简历
        ///</summary>
        public int? ResumeType { get; set; }

        ///<summary>
        ///1-public；2-only nchr;3-confidential;4-private
        ///</summary>
        public int? PrivacyStatus { get; set; }

        ///<summary>
        ///
        ///</summary>
        public int? Integrity { get; set; }

        ///<summary>
        ///
        ///</summary>
        public Guid JobseekerId { get; set; }

        public virtual Jobseeker Jobseeker { get; private set; }

        public virtual ICollection<Education> Educations {
            get {
                if (_educations == null)
                    _educations = new HashSet<Education>();

                return _educations;
            }
            set {
                _educations = new HashSet<Education>(value);
            }
        }

        #endregion

        #region Public Methods

        public Education AddEducationEntry(int schoolTypeCode,
            string school,
            string startYear,
            string endYear,
            string college,
            int? majorCode,
            int educationLevelCode,
            string notes,
            int provinceCode,
            int cityCode) {

            // check procondition
            var newEducation = new Education() {
                SchoolTypeCode = schoolTypeCode,
                School = school,
                StartYear = startYear,
                EndYear = endYear,
                College = college,
                MajorCode = majorCode,
                EducationLevelCode = educationLevelCode,
                Notes = notes,
                ProvinceCode = provinceCode,
                CityCode = cityCode,
                DateCreated= DateTime.Now,
                LastUpdated = DateTime.Now,
                ResumeId = this.Id
            };

            newEducation.GenerateNewIdentity();

            this.Educations.Add(newEducation);

            return newEducation;
        }

        public void SetPrivacyStatus(int statuscode) {
            this.PrivacyStatus = statuscode;
        }

        public void SetTheJobseekerForThisReume(Jobseeker jobseeker) {
            if (jobseeker == null) {
                throw new ArgumentException("argumentException");

                this.Jobseeker = jobseeker;
                this.JobseekerId = jobseeker.Id;
            }
        }

        public Skill AddSkillEntry() {
            return new Skill();
        }
        #endregion

        #region IValidatableObject Members
        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
            var validationResults = new List<ValidationResult>();

            return validationResults;
        }
        #endregion

    }
}
